package logic

import (
	"context"
	"produce/model/mysql"

	"produce/producerpc/internal/svc"
	"produce/producerpc/producerpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLogic {
	return &ListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ListLogic) List(in *producerpc.ListRequest) (*producerpc.ListResponse, error) {
	// todo: add your logic here and delete this line

	var lists []mysql.User
	mysql.DB.Debug().Find(&lists)

	var liststruct []*producerpc.Liststruct

	for _, list := range lists {
		user := producerpc.Liststruct{
			Tel:      list.Tel,
			Password: list.Password,
		}
		liststruct = append(liststruct, &user)
	}
	return &producerpc.ListResponse{List: liststruct}, nil
}
